//lucky_wheel_contrl

// ignore_for_file: non_constant_identifier_names

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:verse_systems/net/http_dio.dart';
import 'package:verse_systems/pages/home/home_control.dart';
import 'package:verse_systems/pages/lucky/lucky_wheel_state.dart';
import 'package:verse_systems/utils/account_util.dart';
import 'package:verse_systems/utils/loading.dart';
import 'package:verse_systems/widgets/alert.dart';

class LuckyWheelContrl extends GetxController {
  final LuckyWheelState state = LuckyWheelState();
  
    final home_control = Get.find<HomeControl>();

 
 //luckyTakesUrl

handleLuckyTakes() async {
  final String token = await AccountUtil.getUserToken();
    Request.postCallback(
      HttpUrls.luckyTakesUrl,
      data: {'token': token},
      success: (res) async {
        ResultData result = ResultData.fromJson(res.data);
        if (result.status == 0) {
          debugPrint("luckyTakes ----->$result");
          state.rules_tips =  result.data["tips"];
          update();
        }
      },
    );
}

  handleLuckyWheel() async {
    final String token = await AccountUtil.getUserToken();
    Request.postCallback(
      HttpUrls.luckyUrl,
      data: {'token': token},
      success: (res) async {
        ResultData result = ResultData.fromJson(res.data);
        if (result.status == 0) {
          debugPrint("luckyUrl ----->$result");
          state.prize_name = result.data["prize_name"].toString(); 
          state.roulette_prizes_id = result.data["roulette_prizes_id"].toString(); 
          state.tips = result.data["tips"]; 
          showlucky();
        }else{
          Loading.showError(result.msg);
        }
      },
    );
  }

  showlucky() {
    Alert.showlucky(
      prize_name: state.prize_name, 
      tips: state.tips, 
      onPressed:home_control.applyOrders);
  }

  @override
  void onInit() {
    super.onInit();
    handleLuckyTakes();
  }
}
